package com.heima.gateway.filter;

import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

@Component
public class MyGlobalFilter implements GlobalFilter, Ordered {
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        //1.获取请求信息
        ServerHttpRequest request = exchange.getRequest();
        //2.处理请求信息
        System.out.println("request.getPath() = " + request.getPath());
        //3.放行
//        return chain.filter(exchange);
        return chain.filter(exchange).then(Mono.fromRunnable(() -> {
            System.out.println("结束");
        }));

    }

    @Override
    public int getOrder() {
        //优先级，数值越小优先级越高
        return 0;
    }
}
